import express from "express";
import { sum } from "./add.js";
const app = express();
const port = 3000;
// 定义根路径的路由处理器
app.get("/", (req, res, next) => {
  try {
    res.send(`sum is ${sum(2, 5)}`);
  } catch (error) {
    next(error); // 将错误传递给下一个中间件
  }
});

// 错误处理中间件
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send("Something broke!");
});

// 启动应用并监听指定端口
app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});
